var userId = localStorage.getItem("userId");
function aa(){
	localStorage.setItem("userId","");
	$(".hideBox .loginaBox").show();
	$(".hideBox .inforBox").hide();
}
$(".headerBox").load("header.html",function(){
	//用于判断的登陆状态
	function getState(){
		
		if(localStorage.getItem("userId")){
			
			$(".hideBox .loginaBox").hide();
			
			$(".hideBox .inforBox").show();
			$.ajax({
					type:"POST",
					url:ptms.url.common.mySelf.mySelf,
					data:{
						userId:userId,
					},
					success:function(data){
						
						var html = "";
						html += '<li><a href="myTrain.html">我的学习</a></li>' + 
									'<li><a href="#">' + data.data.znname + '</a></li>' + 
									'<li class="quit" onclick="aa()">退出</li>'
							
						$(".informationB").html(html);
					}
					
				})
			
		}else{
			
			$(".hideBox .loginaBox").show();
			$(".hideBox .inforBox").hide();
		}
	}
	getState();
});
$(".footer").load("footer.html");

//获取couserID
var coursesId = window.location.search.split("=")[1];




//课程信息的接口
$.ajax({
	type:"POST",
	url:ptms.url.common.courseManger.courseItem,
	async:true,
	data:{"id":coursesId},
	success:function(data){
		var html = "";
		html += '<div class="subjectImgBox container">' + 
			'<div class="row">'  + 
				'<img src="' + ptms.address2  + data.coursesPhotoUrl + '" class="img-responsive"/>' + 
				'<div class="addClassButton">'  + 
					'加入<br/>课程' + 
				'</div>' + 
			'</div>' + 
			
		'</div>' +
		'<div class="container">' + 
			'<div class="row classInformation">' + 
				'<div class="pull-left leftDiv">' + 
					'<p class="firstP">参与人数:</p> ' + 
					'<p class="secondP">' + data.userCount + '</p>' + 
					'<p class="thirdP">课程讲师</p>' + 
					'<ul class="fourP">' + 

					'</ul>' + 
				'</div>' + 
				'<div class="pull-left rightDiv">' + 
					'<p class="classTitle pl">' + data.coursesChnName + '</p>' + 
					'<div>' + 
						'<p class="titleClass pl">课程简介</p>' + 
						'<div class="classContent pl pr pt pb">' + data.coursesIntro  +'</div>' +
					'</div>' + 
					'<div class="catalog">' + 
						'<p class="titleClass pl">专题目录</p>' + 
						'<ul class="classCatalog pl pr pt pb">' + 



						'</ul>' + 
					'</div>' + 
					'<div class="teacherInformationBox">' + 
						'<p class="titleClass pl">课程讲师</p>' + 
						'<div class="classContent pl pr pt pb clearfix bb">' + 

						'</div>' +
					'</div>' + 
				'</div>' + 
			'</div>' + 
		'</div>'
				
	$("#classBriefFree .main").html(html);
	
		//课程专题的接口
		$.ajax({
			type:"GET",
			url:ptms.url.common.courseManger.courseItemSubjectList,
			data:{
				"coursesId":coursesId
			},
			success:function(data){
				var html1 = "";
				var arr = ["一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","二十一","二十二","二十三","二十四","二十五"]
				$.each(data, function(i,o) {
					html1 += "<li>专题" +arr[i] + "：" + o.spcSubName + "</li>"
				});
				$(".classCatalog").html(html1);
			}
		});
	
		//课程讲师的接口
		$.ajax({
			type:"GET",
			url:ptms.url.common.other.exportList,
			async:true,
			data:{
				"coursesId":coursesId
			},
			success:function(data){
				var html2 = "";
				html2 += '<img src="' + data[0].photoUrlLarge + '" class="pull-left" />' + 
					'<div class="pull-left teacherInformation">' + 
						'<p class="name">' + data[0].znname + '</p>' + 
						'<p class="descroation">' + data[0].remark + '</p>' + 
					'</div>'
					
				$(".classContent.bb").html(html2);	
			}
		});
		//点击按钮加入课程的接口	
		$(".addClassButton").click(function(){
			
			//这里是判断用户是否处于登陆状态
			//表示用户已经登陆状态
			if(localStorage.getItem("userId")){
				$.ajax({
					type:"GET",
					url:ptms.url.common.courseManger.addClass,
					data:{
						"userId":userId,
						"coursesId":coursesId
					},
					success:function(data){
						if(data.code != 1){
							alert(data.data);
						}
					}
				})
			}else{
				alert("您还没有登陆，请登录")
				window.location.href = "register.html"
			}
							
				
			})
		
	}
});



